package Test;

import java.awt.BorderLayout;
import java.awt.EventQueue;

import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.border.EmptyBorder;
import javax.swing.JScrollPane;
import javax.swing.JTextArea;
import javax.swing.JButton;

import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;
import java.util.Arrays;

public class Lotoo extends JFrame {

	private JPanel contentPane;
	private JScrollPane scrollPane;
	private JTextArea result;
	private JButton btnNewButton;
	private JButton btnNewButton_1;
	private JButton btnNewButton_2;
	private JButton btnNewButton_3;

	/**
	 * Launch the application.
	 */
	public static void main(String[] args) {
		EventQueue.invokeLater(new Runnable() {
			public void run() {
				try {
					Lotoo frame = new Lotoo();
					frame.setVisible(true);
				} catch (Exception e) {
					e.printStackTrace();
				}
			}
		});
	}

	/**
	 * Create the frame.
	 */
	public Lotoo() {
		setTitle("대박을 꿈꾸며");
		setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		setBounds(100, 100, 450, 300);
		contentPane = new JPanel();
		contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
		setContentPane(contentPane);
		contentPane.setLayout(null);
		contentPane.add(getScrollPane());
		contentPane.add(getBtnNewButton());
		contentPane.add(getBtnNewButton_1());
		contentPane.add(getBtnNewButton_2());
		contentPane.add(getBtnNewButton_3());
	}

	private JScrollPane getScrollPane() {
		if (scrollPane == null) {
			scrollPane = new JScrollPane();
			scrollPane.setBounds(12, 10, 410, 114);
			scrollPane.setViewportView(getResult());
		}
		return scrollPane;
	}

	private JTextArea getResult() {
		if (result == null) {
			result = new JTextArea();
		}
		return result;
	}

	private JButton getBtnNewButton() {
		if (btnNewButton == null) {
			btnNewButton = new JButton("lotoo");
			btnNewButton.addActionListener(new ActionListener() {
				public void actionPerformed(ActionEvent arg0) {
					// 1~10번까지 랜덤하게 나오게 하시오.
					int i = (int) (Math.random() * 10) + 1;
					result.append("1~10 :" + i);
					result.append("\n");
				}
			});
			btnNewButton.setBounds(12, 134, 97, 23);
		}
		return btnNewButton;
	}

	private JButton getBtnNewButton_1() {
		if (btnNewButton_1 == null) {
			btnNewButton_1 = new JButton("lotoo1");
			btnNewButton_1.addActionListener(new ActionListener() {
				public void actionPerformed(ActionEvent arg0) {
					// 20~80까지 랜덤하게 뽑아보자
					int i = (int) (Math.random() * 61) + 1;
					result.append("20~80: " + i);
					result.append("\n");
				}
			});
			btnNewButton_1.setBounds(121, 134, 97, 23);
		}
		return btnNewButton_1;
	}

	private JButton getBtnNewButton_2() {
		if (btnNewButton_2 == null) {
			btnNewButton_2 = new JButton("lotoo2");
			btnNewButton_2.addActionListener(new ActionListener() {
				public void actionPerformed(ActionEvent arg0) {
					int[] lo = new int[6];
					result.append("--------------------------\n");
					for(int i=0;i<lo.length;i++){
						lo[i] = (int)(Math.random()*45)+1;
						for(int j=i-1;j>=0;j--){
							if(lo[i]==lo[j]){
							i--;
							break;
						}
					}
					}
					Arrays.sort(lo);
					result.append(Arrays.toString(lo));
					result.append("\n");
				}
				
			});
			btnNewButton_2.setBounds(230, 134, 97, 23);
		}
		return btnNewButton_2;
	}
	private JButton getBtnNewButton_3() {
		if (btnNewButton_3 == null) {
			btnNewButton_3 = new JButton("lotoo3");
			btnNewButton_3.addActionListener(new ActionListener() {
				public void actionPerformed(ActionEvent arg0) {
					int[] base = new int[45];
					int[] lo = new int[6];
					int temp = 0;
					for(int i=1;i<46;i++)
						base[i-1]=i;
						for(int i=0;i<1000;i++){
							int k =(int)(Math.random()*44)+1;
							temp = base[0];
							base[0]=base[k];
							base[k]=temp;	
						}
						System.arraycopy(base, 0, lo, 0, 6);
						Arrays.sort(lo);
						result.append(Arrays.toString(lo));
						result.append("\n");
					}
				
			});
			btnNewButton_3.setBounds(337, 134, 97, 23);
		}
		return btnNewButton_3;
	}
}
